/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;

import doan.quanlycanbo.portlet.NoSuchchucvuException;
import doan.quanlycanbo.portlet.model.chucvu;
import doan.quanlycanbo.portlet.service.base.chucvuLocalServiceBaseImpl;

import java.util.List;
/**
 *
 * @author Nguyen Tuan Vinh
 */
public class chucvuLocalServiceImpl extends chucvuLocalServiceBaseImpl {
	
	public chucvu getChucvu(long idChucvu) throws NoSuchchucvuException, SystemException{
		return chucvuPersistence.findByPrimaryKey(idChucvu);
	}
	
	public List<chucvu> getAll() throws SystemException{
		return chucvuPersistence.findAll();
	}
	
	public List<chucvu> getChucvuByGroup(long groupId) throws SystemException{
		return chucvuPersistence.findByG(groupId);
	}
	
	public List<chucvu> getChucvuByG_L(long groupId, String languageId) throws SystemException{
		return chucvuPersistence.findByG_L(groupId, languageId);
	}
	
	public chucvu addChucVu(chucvu cv1, long userId) throws SystemException{
		long machucvu = CounterLocalServiceUtil.increment(chucvu.class.getName());
		chucvu cv2 = chucvuPersistence.create(machucvu);
		
		cv2.setGroupId(cv1.getGroupId());
		cv2.setCompanyId(cv1.getCompanyId());
		cv2.setLanguageId(cv1.getLanguageId());
		cv2.setTenchucvu(cv1.getTenchucvu());		

		try {
			resourceLocalService.addResources(cv1.getCompanyId(), cv1.getGroupId(), userId, 
						chucvu.class.getName(), cv2.getPrimaryKey(), false, true, true);
		} catch (PortalException e) {
			e.printStackTrace();
		}
		
		return chucvuPersistence.update(cv2, false);
	}
	
	public chucvu updateChucVu(long machucvu, String tenchucvu) throws NoSuchchucvuException, SystemException{
		chucvu cv = chucvuPersistence.findByPrimaryKey(machucvu);
		cv.setTenchucvu(tenchucvu);
		return cv;
	}
	
	public void deleteChucVu(long machucvu) throws NoSuchchucvuException, SystemException,PortalException{
		chucvu cv = chucvuPersistence.findByPrimaryKey(machucvu);
		deleteChucVu(cv);
	}
	
	public void deleteChucVu(chucvu cv) throws SystemException,PortalException{
		resourceLocalService.deleteResource(cv.getCompanyId(), chucvu.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, cv.getPrimaryKey());
		chucvuPersistence.remove(cv);
	}
}










